package com.room.service;

import com.room.mapper.ApartmentMapper;
import com.room.pojo.Apartment;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @创建人 lin
 * @创建时间 2019/10/6
 * @描述
 */
@Service
public class ApartmentService {

    @Autowired
    ApartmentMapper apartmentMapper;

    //修改公寓数据
    public int updateApartment(Apartment apartment){
       return  apartmentMapper.updateByPrimaryKey(apartment);
    }

    //根据传进的id删除学生数据
    public boolean deleteApartById(String ids){
        String[] split = ids.split(",");
        return apartmentMapper.deleteApartById(split) == split.length;
    }

    //根据分页数据获取所有公寓
    public List<Apartment> getApartmentByPage(Integer page, Integer size){
        int start = (page-1) * size;
        return apartmentMapper.getApartmentByPage(start,size);
    }

    //获取公寓表总数
    public Long getApartmentCount(){
        return apartmentMapper.getApartmentCount();
    }

    //获取所有公寓的数据用来初始化下拉菜单
    public List<Apartment> getAllApartment(){
        return apartmentMapper.getAllApartment();
    }

   public String getMaxId(){
        return apartmentMapper.getMaxId();
   }

   //添加公寓
   public int inserApartment(Apartment apartment){
        return apartmentMapper.insert(apartment);
   }

}
